using Engine;
using Game;

namespace SCIENEW {
    public class FluidTankTransferrer : FluidTransferrer{
        public FluidTankTransferrer(Point3 position, SubsystemTerrain subsystemTerrain) : base(position, subsystemTerrain) { }

        public override ITank GetTank() {
            //更新实体组件
            ComponentBlockEntity componentBlockEntity;
            Point3 point = Position;
            while (!DeviceEntityUtils.GetDeviceEntity(SubsystemTerrain.Project.FindSubsystem<SubsystemTerrain>(true), point, out componentBlockEntity) || componentBlockEntity.Entity.FindComponent<ComponentFluidTank>() == null) {
                point -= Point3.UnitY;
                if (point.Y <= 0) return null;
            }
            return componentBlockEntity.Entity.FindComponent<ComponentFluidTank>(true);
        }

        public override int RemoveFluid(ITank tank, float volume, out float removedVolume, out int removedTankIndex) {
            if (tank.GetTankVolume(0) <= 0) return base.RemoveFluid(tank, volume, out removedVolume, out removedTankIndex);

            int fluidValue = tank.GetTankValue(0);
            removedVolume = tank.RemoveTankFluid(0, volume);
            removedTankIndex = 0;
            return fluidValue;
        }

        public override bool IsFull(ITank tank) {
            return tank.GetTankVolume(0) >= tank.GetTankOriginalCapacity(0);
        }
    }
}